#ifndef DATAPROTOCOL_H_
#define DATAPROTOCOL_H_

#include "../../include/dto/3d/matrix.h"

class DisplayProtocol {
public:
	static VideoDisplay* getVideoDisplay(AttributeHolder *attribs) {
		DataPool *pool = attribs->getPool();
		VideoDisplay *display = (VideoDisplay*)pool->getRootModel("display");
		return display;
	}
	
	static Texture* getPreviewTexture(AttributeHolder *attribs) {
		VideoDisplay *display = getVideoDisplay(attribs);
		return display->preview->get()->text->get();
	}
	
	static Texture* getSelectedTexture(AttributeHolder *attribs) {
		VideoDisplay *display = getVideoDisplay(attribs);
		int selected = display->selected->get();
		return getTextureByNumber(attribs,selected);
	}
	
	static Texture* getTextureByNumber(AttributeHolder *attribs,int selected) {
		DisplayPanel *p = getPanelByNumber(attribs,selected);
		return p->text->get();
	}
	
	static DisplayPanel* getPanelByNumber(AttributeHolder *attribs,int selected) {
		VideoDisplay *display = getVideoDisplay(attribs);
		std::string panelName;
		if (selected==5) {
			panelName="preview";
		}
		else {
			std::ostringstream os;
			os << "source" << selected;
			panelName = os.str();
		}
		DisplayPanel *p = ((Prop<DisplayPanel*>*)display->getProp(panelName))->get();
		return p;
	}
	
};

#endif /*DATAPROTOCOL_H_*/
